package com.gitee.feizns;

import com.gitee.feizns.quickstart.spring.aop.Proxy;
import org.aopalliance.aop.Advice;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.aop.AfterReturningAdvice;

import java.lang.reflect.Method;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        Hello original = hello -> System.out.println("HELLO WORLD!!!");

        Hello hello = Proxy.getProxy(original, Hello.class, invocation -> {
            System.out.println("BEFORE");
            try {
                return invocation.proceed();
            } catch (Throwable e) {
                throw new RuntimeException(e);
            }
        });
        System.out.println(hello);
//        System.out.println();
//        hello.hello("hello");
//        Hello hello = ProxyFactory.getProxy(Hello.class, (MethodInterceptor) invocation -> {
//            System.out.println("BEFORE");
//            Method method = invocation.getMethod();
//            method.invoke(original);
//            System.out.println("AFTER");
//            return method;
//        });

//        hello.hello();
    }

    public interface Hello {
        void hello(String hello);
    }

    @Aspect
    public static class Test implements Advice {

        @Before("execution(* com.**.*(..))")
        public void test() {
            System.out.println("test");
        }

    }

    public static class TestBefore implements AfterReturningAdvice {


        @Override
        public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
            System.out.println("返回值是：" + returnValue);
        }

    }
}
